package com.wannengbang.cloudleader.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.TransformListBean;
import com.wannengbang.cloudleader.utils.DateTimeUtil;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 合伙人列表
 */
public class TransformListAdapter extends RecyclerView.Adapter<TransformListAdapter.ViewHolder> {

    private List<TransformListBean.DataBean.ItemListBean> listsBeans;
    private Context context;

    public TransformListAdapter(List<TransformListBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_exchange_transfor_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TransformListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        holder.tvCreateTime.setText("创建时间：" + DateTimeUtil.format7(new Date(Long.parseLong(dataBean.getCreate_time()) * 1000)));
        holder.tvSnNo.setText("SN编号:" + dataBean.getSn());
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_sn_no)
        TextView tvSnNo;
        @BindView(R.id.tv_create_time)
        TextView tvCreateTime;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
